package com.eastfair.venueservice.service.impl;

import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.api.ReportDrawingCategoryAuditHistoryFeign;
import com.eastfair.home.dto.ReportDrawingCategoryAuditHistoryDTO;
import com.eastfair.home.enumeration.ReportDrawingCategoryAuditDrawingAuditStatusEnum;
import com.eastfair.venueservice.dto.HomeBuilderDrawingCategoryAuditHistoryDTO;
import com.eastfair.venueservice.entity.HomeBuilderDrawingCategoryAuditHistory;
import com.eastfair.venueservice.enumeration.HomeBuilderDrawingCategoryAuditAuditStatusEnum;
import com.eastfair.venueservice.service.VenueManageReportDrawingCategoryAuditHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 主场图纸分类审核历史 service.
 *
 * @author dqq
 * @date 2023 /5/4
 */
@Service
@Slf4j
public class VenueManageReportDrawingCategoryAuditHistoryServiceImpl implements VenueManageReportDrawingCategoryAuditHistoryService {

    @Resource
    private ReportDrawingCategoryAuditHistoryFeign reportDrawingCategoryAuditHistoryFeign;

    @Override
    public boolean updateVenueAuditStatus(ReportDrawingCategoryAuditHistoryDTO historyDTO) {
        log.info("updateVenueAuditStatus - 场馆审核更新审核历史, historyDTO={}", historyDTO);
        R<Boolean> result = reportDrawingCategoryAuditHistoryFeign.updateVenueAuditStatus(historyDTO);
        log.info("updateVenueAuditStatus - 场馆审核更新审核历史, result={}", result);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }

    @Override
    public boolean updateVenueAuditStatus(HomeBuilderDrawingCategoryAuditHistory history) {
        // 更新审核历史
        ReportDrawingCategoryAuditHistoryDTO reportHistoryDTO = new ReportDrawingCategoryAuditHistoryDTO();
        reportHistoryDTO.setReportSpaceId(history.getReportId());
        reportHistoryDTO.setDrawingCategoryId(history.getDrawingId());
        reportHistoryDTO.setVenueAuditStatus(history.getAuditStatus());
        reportHistoryDTO.setVenueAuditOpinion(history.getAuditOpinion());
        reportHistoryDTO.setVenueAuditTime(history.getAuditTime());
        reportHistoryDTO.setVenueAuditUserId(history.getAuditUserId());
        reportHistoryDTO.setVenueAuditUserName(history.getAuditUserName());
        if (HomeBuilderDrawingCategoryAuditAuditStatusEnum.APPROVED.eq(history.getAuditStatus())) {
            reportHistoryDTO.setDrawingAuditStatus(ReportDrawingCategoryAuditDrawingAuditStatusEnum.APPROVED.getCode());
        } else {
            reportHistoryDTO.setDrawingAuditStatus(ReportDrawingCategoryAuditDrawingAuditStatusEnum.NOT_APPROVED.getCode());
        }
        return updateVenueAuditStatus(reportHistoryDTO);
    }
}